<template>
  <div>
    <Main type="form">
      <el-form
        ref="form"
        label-width="160px"
        label-position="right"
        :model="form"
      >
        <el-form-item label="商品评论">
          <el-switch
            v-model="send"
            :active-text="send == false ? '已关闭' : '已打开'"
          >
          </el-switch>
        </el-form-item>
        <el-form-item
          label="买家发起退款申请"
          prop="num1"
          :rules="{
            required: true,
            message: '请输入天数',
            trigger: 'blur'
          }"
        >
          <el-input-number
            v-model="form.num1"
            size="mini"
            :min="0"
            :max="90"
            :precision="0"
            :controls="false"
          ></el-input-number
          >&nbsp;&nbsp; 天后买家未评论，系统将自动评论。
          <div>
            系统默认时间7天，手动设置时间最长不超过90天。评价内容为：“用户超时未评，系统自动好评”
          </div>
        </el-form-item>
        <el-form-item label="评论默认显示">
          <el-switch
            v-model="sendout"
            :active-text="sendout == false ? '已关闭' : '已打开'"
          >
          </el-switch>
        </el-form-item>
      </el-form>
    </Main>
    <Footer>
      <el-button type="primary" @click="submit">保 存</el-button>
    </Footer>
  </div>
</template>
<script>
import { COMMENTSET } from "../../service";
export default {
  data() {
    return {
      send: false,
      sendout: false,
      form: {
        num1: 0
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      await COMMENTSET({}).then(({ code, data }) => {
        if (code === 200) {
          this.send = data.is_allow === 1;
          this.sendout = data.is_show === 1;
          this.form.num1 = data.auto_comment;
        }
      });
    },
    async submit() {
      await this.$refs["form"].validate(valid => {
        if (valid) {
          COMMENTSET({
            flag: "save",
            is_allow: this.send ? 1 : 0,
            auto_comment: this.form.num1,
            is_show: this.sendout ? 1 : 0
          }).then(res => {
            if (res.code === 200) {
              this.$message({
                message: "设置成功",
                type: "success"
              });
            }
          });
        }
      });
    }
  }
};
</script>
